/*
 * @Date: 2022-11-07 10:42:06
 * @LastEditors: Please set LastEditors
 * @gitee: https://gitee.com/chun22222222
 * @github: https://github.com/chun222
 * @Desc:
 * @LastEditTime: 2023-08-23 17:20:19
 * @FilePath: \web\src\core\tools\storage.js
 */

const pre = "TMES_";
export const StorageName = {
  language: pre + "LANGUAGE",
  fontsize: pre + "FONTSIZE",
  user_tabs: pre + "USER_TABS",
  user_info: pre + "USER_INFO",
  user_token: pre + "USER_TOKEN",
  user_routes: pre + "USER_ROUTES",
  layout: pre + "LAYOUT",
  serverIndex: pre + "SERVER_INDEX",
  theme: pre + "THEME",
  clientMode: pre + "CLIENT_MODE",
  clientConfig: pre + "CLIENT_CONFIG",
  runwo_woSelected: pre + "RUNWO_WOSELECTED",
  runwo_woList: pre + "RUNWO_WOLIST",
  runwo_mode: pre + "MESRUN_MODE"
};

/**
 * 存储对象
 * @param key
 * @param value
 */
export const setStorage = function (key, value) {
  localStorage.setItem(key, JSON.stringify(value));
};

/**
 * 获取对象
 * @param key
 */
export const getStorage = function (key) {
  if (localStorage.getItem(key) == null) {
    return null;
  }
  //判断能否转换为json对象

  try {
    return JSON.parse(localStorage.getItem(key));
  } catch (e) {
    return localStorage.getItem(key);
  }

  // return JSON.parse(localStorage.getItem(key));
};

/**
 * 删除对象
 * @param key
 */
export const delStorage = function (key) {
  localStorage.removeItem(key);
};
